<?php

class CatController extends FrontBaseC {

    /**
     * Declares class-based actions.
     */
    public function actions() {
        
    }

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex() {
        $CategoryModel = new CategoryModel();
        $cid = Yii::app()->request->getParam('cid');
        if ($cid) {
            $cat = $CategoryModel->getCategory($cid);
            $keys = SeoWord::getCatSeo();
            $cat_seo = $keys[$cat['class_name']];
            $this->description = $cat_seo['Description'];
            $this->keywords = $cat_seo['keywords'];
            $this->title = $cat_seo['title'];
        }
        $GoodsModel = new GoodsModel();
        if (isset($_GET['cid']) && isset($_GET['timeico']) && $_GET['timeico'] == 'y') {
            $home_goods = $GoodsModel->getCatYesterdayGoods(ConfigModel::model()->getConfig('home_num'));
            $this->render('goodlist', array(
                'home_goods' => $home_goods[0],
                'pages' => $home_goods[1],
                'cid' => $_GET['cid'],
                'timeico' => 'y',
            ));
            return;
        }

        $home_goods = $GoodsModel->getCatGoods(ConfigModel::model()->getConfig('home_num'));
        $this->render('goodlist', array(
            'home_goods' => $home_goods[0],
            'pages' => $home_goods[1],
            'cid' => $_GET['cid'],
            'timeico' => 'td',
        ));
    }

    public function actionYesterday() {
        SeoWord::setWord($this, 'getCatSeo', 'yesterday');
        $GoodsModel = new GoodsModel();
        if (isset($_GET['cid']) && !isset($_GET['timeico'])) {
            $home_goods = $GoodsModel->getCatYesterdayGoods(ConfigModel::model()->getConfig('home_num'));
            $page_model = self::page($home_goods[1]->itemCount, $home_goods[1]->getLimit(), $home_goods[1]->currentPage + 1, array('isrule' => true, 'rule' => array('index' => '/ycid/' . (int) $_GET['cid'] . '.html', 'list' => '/front/cat/yesterday/cid/' . (int) $_GET['cid'] . '/page/*.html')));
            $pages = $page_model->show();
            $this->render('yesterday', array(
                'home_goods' => $home_goods[0],
                'pages' => $pages,
                'cid' => $_GET['cid'],
                'timeico' => 'y',
            ));
            return;
        }

        $home_goods = $GoodsModel->getCatGoods(ConfigModel::model()->getConfig('home_num'));
        $page_model = self::page($home_goods[1]->itemCount, $home_goods[1]->getLimit(), $home_goods[1]->currentPage + 1, array('isrule' => true, 'rule' => array('index' => '/front/cat/yesterday/timeico/td/cid/' . (int) $_GET['cid'] . '.html', 'list' => '/front/cat/yesterday/cid/' . (int) $_GET['cid'] . '/timeico/td/page/*.html')));
        $pages = $page_model->show();
        $this->render('yesterday', array(
            'home_goods' => $home_goods[0],
            'pages' => $pages,
            'cid' => $_GET['cid'],
            'timeico' => 'td',
        ));
    }

    public function actionTomorrow() {
        //SeoWord::setWord($this, 'getCatSeo', 'tomorrow');
        $GoodsModel = new GoodsModel();
        $home_goods = $GoodsModel->getTomorrowGoods(40);
        $page_model = self::page($home_goods[1]->itemCount, $home_goods[1]->getLimit(), $home_goods[1]->currentPage + 1, array('isrule' => true, 'rule' => array('index' => '/tomorrow.html', 'list' => '/front/cat/tomorrow/page/*.html')));
        $pages = $page_model->show();
        $this->render('/index/noTitleGoodlist', array(
            'home_goods' => $home_goods[0],
            'pages' => $pages,
        ));
    }

    public function actionJj() {
        //SeoWord::setWord($this, 'getCatSeo', 'jkj');
        $GoodsModel = new GoodsModel();
        $home_goods = $GoodsModel->getJKJGoods(ConfigModel::model()->getConfig('home_num'));
        $page_model = self::page($home_goods[1]->itemCount, $home_goods[1]->getLimit(), $home_goods[1]->currentPage + 1);
        $pages = $page_model->show();
        $this->render('jj', array(
            'home_goods' => $home_goods[0],
            'pages' => $pages,
        ));
    }

    public function actionJd() {
        $this->layout = 'theme.views.layouts.NoCatContent';

        $GoodsModel = new GoodsModel();
         $where = array(
            'start_time' => array('LT', strtotime("2014-11-12 00:00:00")),
            'end_time' => array('GT', time()),
        );
        $home_goods = $GoodsModel->getSpecialGoods(5, 0, $where);
        //var_dump($home_goods);exit();
        //20个小时内只显示一次
        $value = $this->getCookie('double_11');
        if (empty($value)) {
            $this->setCookie('double_11', $value, time() + 60 * 60 * 20);
            $result = true;
        } else
            $result = false;

        $this->render('double-11', array(
            'home_goods' => $home_goods,
            'result' => $result
        ));
    }

    public function actionLocationTJ() {
        header("Location: http://www.9w9w.cn/zt820");
        exit;
    }

}
